// shortcut to the SPARQL endpoint cataloging TCGA files
// http://tcga.github.com/?module=http://tcgapps.googlecode.com/git/catalog.js // real link
// http://tcga.github.com/?module=http://localhost:8888/tcgapps/catalog.js // dev link


(function(){
	console.log('catalog loaded :-)');
	if ($("#catalogHead").length==0){ // if catalog tab head was not created already
		jQuery(".nav").append('<li><a id="catalogHead" href="#catalogBody" data-toggle="tab">Catalog</a></li>')
	}
	if (jQuery("#catalogBody").length==0){ // if catalog tab body was not created already
		jQuery("body > #main").prepend('<div id="catalogBody" class="tab-pane"><div class="page-header"><h1>SPARQL endpoint</h1></div></div>')
	}
	$("#catalogBody").append('<p><button id="rmCatalog" style="color:red">Remove Catalog</button></p>');
	$("#rmCatalog")[0].onclick=function(){TCGA.catalog.GUI.remove()};
	$("#catalogBody").append('<span><b>Sample queries:</b> <button id="platformDisease">Platform|Disease</button><button id="filesDate">Date files added</button><button id="filesDisease">count files per disease</button><button id="agruenebergRppa">level 3 RPPA data for GBM</button><button id="gbmTCGA-06-0190">GBM datafiles for patient TCGA-06-0190</button></span>');
	$("#platformDisease")[0].onclick=function(){TCGA.catalog.GUI.sampleQueries('http://agalpha.mathbiol.org/repositories/tcga#query/r/platformDisease')};
	$("#filesDate")[0].onclick=function(){TCGA.catalog.GUI.sampleQueries('http://agalpha.mathbiol.org/repositories/tcga#query/r/Files%20Added%20by%20Date')};
	$("#filesDisease")[0].onclick=function(){TCGA.catalog.GUI.sampleQueries('http://agalpha.mathbiol.org/repositories/tcga#query/r/Files%20by%20Disease')};
	$("#agruenebergRppa")[0].onclick=function(){TCGA.catalog.GUI.sampleQueries('http://agalpha.mathbiol.org/repositories/tcga#query/r/agrueneberg-tcga-gbm-rppa-level3')};
	$("#gbmTCGA-06-0190")[0].onclick=function(){TCGA.catalog.GUI.sampleQueries('http://agalpha.mathbiol.org/repositories/tcga#query/r/GBM-DataForPatient_TCGA-06-0190')};
	
	
	$("#catalogBody").append('<span id="catalogIframe"><iframe src="http://agalpha.mathbiol.org/repositories/tcga#query" width="100%" height="600"></iframe></span>')
	
	
	TCGA.catalog={"GUI":{}}; // keep GUI functions here
	TCGA.catalog.GUI.sampleQueries=function(url){
		$('#catalogIframe').remove();
		$("#catalogBody").append('<span id="catalogIframe"><iframe src="'+url+'" width="100%" height="600"></iframe></span>')
	}
	TCGA.catalog.GUI.remove=function(){ // remove module
		$('#catalogBody').remove();
		$('#catalogHead').remove();
		$('.nav > li > a')[0].click(); // normally this is the modules tab
	}
	
	$('#catalogHead').click(); // move to Catalog tab
	
})();